{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pandas Series !\n",
    "A 1D array in numpy was called array !, which in pandas it is called a Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    4.0\n",
      "1    5.0\n",
      "2    6.0\n",
      "3    0.1\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "S1 = pd.Series([1,2,3,4])\n",
    "S2 = pd.Series([4,5,6, 0.1])\n",
    "print(S2)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The vectorized operations are exactly like numpy arrays !!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    5.0\n",
      "1    7.0\n",
      "2    9.0\n",
      "3    4.1\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "S3 = S1+S2\n",
    "S4 = S1-S2\n",
    "print(S3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also create logical Series (boolean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    False\n",
      "1    False\n",
      "2    False\n",
      "3     True\n",
      "dtype: bool\n"
     ]
    }
   ],
   "source": [
    "S5 = S1>S2\n",
    "print(S5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also use the awesome logical indexing in pandas (similar to numpy)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    5.0\n",
       "2    6.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S2[3]\n",
    "S2[pd.Series([False,True,True,False])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S1[S1>S2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The awesome thing about pandas is that you can give names to elements (we call them indexes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "S6 = pd.Series([1,3,6,9],[\"a\",\"b\",\"c\",\"d\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a    1\n",
      "b    3\n",
      "c    6\n",
      "d    9\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(S6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's define a vector S7 that is using similar indexes but with a different order "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a    10\n",
      "b     8\n",
      "c    13\n",
      "d    13\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "S6 = pd.Series([1,3,6,9],[\"a\",\"b\",\"c\",\"d\"])\n",
    "S7 = pd.Series([4,5,7,9], [\"d\",\"b\",\"c\",\"a\"])\n",
    "S8 = S6+S7\n",
    "print(S8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can observe that it considers the indexes not the order !! that is a nice advantage !!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's solve out problem using this advantage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wall       1150\n",
      "ceiling    1240\n",
      "door        124\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "Q_heating = pd.Series([1150,1240,124], index= [\"wall\",\"ceiling\", \"door\"])\n",
    "print(Q_heating)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Pay attention that you can create a pandas Series either like this:\n",
    "Q_heating = pd.Series([1150,1240,124], [\"wall\",\"ceiling\", \"door\"])\n",
    "\n",
    "or like this:\n",
    "\n",
    "Q_heating = pd.Series([1150,1240,124], index= [\"wall\",\"ceiling\", \"door\"])\n",
    "\n",
    "Clearly, the second option is better because it is easier to understand\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Furhtermore, you can define a pandas Series by providing a dictionary as the input\n",
    "\n",
    "Pandas_series = pd.Series(youDictionary)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ceiling    1240\n",
      "door        124\n",
      "walls      1150\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "Q_heating_dict = {\"walls\":1150,\"ceiling\":1240,\"door\":124}\n",
    "Q_heating = pd.Series(Q_heating_dict)\n",
    "print(Q_heating)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The fact that we have indexes in pandas Series means that we can use them to extract the elements !"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "124\n"
     ]
    }
   ],
   "source": [
    "Q_door = Q_heating[\"door\"]\n",
    "print(Q_door)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also concert numpy arrays into pandas Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1144.60788"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opqaue_item_array  = np.array([\"wall\",\"ceiling\",\"door\"])\n",
    "opaque_U_array = np.array([0.438,0.25,1.78])\n",
    "opaque_area_array = np.array([105.8,200,2.2])\n",
    "T_inside_heating = 20\n",
    "T_outside_heating = -4.7\n",
    "DeltaT_heating= T_inside_heating - T_outside_heating\n",
    "opaque_HF_array = DeltaT_heating * opaque_U_array\n",
    "opaque_Q_array = opaque_HF_array*opaque_area_array\n",
    "Q_heating = pd.Series(opaque_Q_array, index= opqaue_item_array)\n",
    "Q_heating[\"wall\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Clearly, we could do the whole process using Pandas Series, as follows:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wall       1149.24192\n",
      "ceiling    1240.00000\n",
      "door         97.11680\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "opaque_U = pd.Series([0.438,0.25,1.78], index = [\"wall\",\"ceiling\",\"door\"])\n",
    "opaque_area = pd.Series([105.8,200,2.2], index = [\"wall\",\"ceiling\",\"door\"] )\n",
    "temperatures = pd.Series([20,-4.8], index=[\"T_inside_heating\",\"T_outside_heating\"])\n",
    "opaque_HF = opaque_U * (temperatures[\"T_inside_heating\"]-temperatures[\"T_outside_heating\"])\n",
    "opaque_Q = opaque_HF*opaque_area\n",
    "print(opaque_Q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## applying a function to Series\n",
    "you can use pandas .apply function to apply a function to Series!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wall       1.144608\n",
      "ceiling    1.235000\n",
      "door       0.096725\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "def toKw(inputValue):\n",
    "    outputValue = inputValue/1000\n",
    "    return outputValue\n",
    "\n",
    "Q_heating_kw = Q_heating.apply(toKw)\n",
    "print(Q_heating_kw)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pandas DataFrames !\n",
    "Using Pandas DataFrames you can define 2 D matrixes, each column in this matrix can have a different datatype !"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "resistance_names = [\"R1\",\"R2\",\"R3\",\"R4\",\"R5\"]\n",
    "resistances_types = [\"conv\",\"cond\",\"cond\",\"cond\",\"conv\"]\n",
    "resistances_h = [10,None,None,None,25]\n",
    "resistances_k=  [None,0.8,1.5,0.05,None]\n",
    "resistances_L= [None,0.5,0.3,0.6,None]\n",
    "resistances_RValues=[0,0,0,0,0]\n",
    "resistance_listofLists = [resistances_types,resistances_h,resistances_k,resistances_L,resistances_RValues]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "          R1    R2    R3    R4    R5\n",
      "type    conv  cond  cond  cond  conv\n",
      "h         10  None  None  None    25\n",
      "k       None   0.8   1.5  0.05  None\n",
      "L       None   0.5   0.3   0.6  None\n",
      "RValue     0     0     0     0     0\n"
     ]
    }
   ],
   "source": [
    "resistances_DF = pd.DataFrame(resistance_listofLists,\n",
    "                              index=[\"type\",\"h\",\"k\",\"L\",\"RValue\"], \n",
    "                              columns = [\"R1\",\"R2\",\"R3\",\"R4\",\"R5\"])\n",
    "print(resistances_DF)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "LEt me transpose it (which means changing the columsn with rows) so that each item would be a row and each property would be columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    type     h     k     L RValue\n",
      "R1  conv    10  None  None      0\n",
      "R2  cond  None   0.8   0.5      0\n",
      "R3  cond  None   1.5   0.3      0\n",
      "R4  cond  None  0.05   0.6      0\n",
      "R5  conv    25  None  None      0\n"
     ]
    }
   ],
   "source": [
    "resistances_DF2 = resistances_DF.transpose()\n",
    "print(resistances_DF2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Extracting data from DataFrames\n",
    "#### using iloc (number)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.iloc[1,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.iloc[3,3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type      conv\n",
       "h           10\n",
       "k         None\n",
       "L         None\n",
       "RValue       0\n",
       "Name: R1, dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.iloc[0,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "R1    0\n",
       "R2    0\n",
       "R3    0\n",
       "R4    0\n",
       "R5    0\n",
       "Name: RValue, dtype: object"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.iloc[:,-1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type      cond\n",
       "h         None\n",
       "k          1.5\n",
       "L          0.3\n",
       "RValue       0\n",
       "Name: R3, dtype: object"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.iloc[2,:]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### .loc[] Extracting elements using their name !!\n",
    "We do not like the numbers in pandas !\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.5"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.loc[\"R3\",\"k\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type      cond\n",
       "h         None\n",
       "k          1.5\n",
       "L          0.3\n",
       "RValue       0\n",
       "Name: R3, dtype: object"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.loc[\"R3\",:]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type      cond\n",
       "h         None\n",
       "k          1.5\n",
       "L          0.3\n",
       "RValue       0\n",
       "Name: R3, dtype: object"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.loc[\"R3\"]\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Note** For extracting columsn you do not need .loc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "R1      10\n",
       "R2    None\n",
       "R3    None\n",
       "R4    None\n",
       "R5      25\n",
       "Name: h, dtype: object"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2[\"h\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's do the calculation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "      <th>h</th>\n",
       "      <th>k</th>\n",
       "      <th>L</th>\n",
       "      <th>RValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>R1</th>\n",
       "      <td>conv</td>\n",
       "      <td>10</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R2</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R3</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R4</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R5</th>\n",
       "      <td>conv</td>\n",
       "      <td>25</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    type     h     k     L RValue\n",
       "R1  conv    10  None  None      0\n",
       "R2  cond  None   0.8   0.5      0\n",
       "R3  cond  None   1.5   0.3      0\n",
       "R4  cond  None  0.05   0.6      0\n",
       "R5  conv    25  None  None      0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "R1     True\n",
       "R2    False\n",
       "R3    False\n",
       "R4    False\n",
       "R5     True\n",
       "Name: type, dtype: bool"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2[\"type\"]==\"conv\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "R1     0.1\n",
       "R5    0.04\n",
       "Name: h, dtype: object"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1.0/resistances_DF2[resistances_DF2[\"type\"]==\"conv\"][\"h\"]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "R1    0\n",
       "R5    0\n",
       "Name: RValue, dtype: object"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2[resistances_DF2[\"type\"]==\"conv\"][\"RValue\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "      <th>h</th>\n",
       "      <th>k</th>\n",
       "      <th>L</th>\n",
       "      <th>RValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>R1</th>\n",
       "      <td>conv</td>\n",
       "      <td>10</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R2</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R3</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R4</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R5</th>\n",
       "      <td>conv</td>\n",
       "      <td>25</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    type     h     k     L RValue\n",
       "R1  conv    10  None  None    0.1\n",
       "R2  cond  None   0.8   0.5      0\n",
       "R3  cond  None   1.5   0.3      0\n",
       "R4  cond  None  0.05   0.6      0\n",
       "R5  conv    25  None  None   0.04"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.loc[resistances_DF2[\"type\"]==\"conv\",\"RValue\"] = 1.0/resistances_DF2.loc[resistances_DF2[\"type\"]==\"conv\",\"h\"]\n",
    "resistances_DF2\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "R2    0.625\n",
       "R3      0.2\n",
       "R4       12\n",
       "dtype: object"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2.loc[resistances_DF2[\"type\"]==\"cond\",\"L\"]/resistances_DF2.loc[resistances_DF2[\"type\"]==\"cond\",\"k\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "resistances_DF2.loc[resistances_DF2[\"type\"]==\"cond\",\"RValue\"] = resistances_DF2.loc[resistances_DF2[\"type\"]==\"cond\",\"L\"]/resistances_DF2.loc[resistances_DF2[\"type\"]==\"cond\",\"k\"]\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>type</th>\n",
       "      <th>h</th>\n",
       "      <th>k</th>\n",
       "      <th>L</th>\n",
       "      <th>RValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>R1</th>\n",
       "      <td>conv</td>\n",
       "      <td>10</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R2</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R3</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R4</th>\n",
       "      <td>cond</td>\n",
       "      <td>None</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.6</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R5</th>\n",
       "      <td>conv</td>\n",
       "      <td>25</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    type     h     k     L RValue\n",
       "R1  conv    10  None  None    0.1\n",
       "R2  cond  None   0.8   0.5  0.625\n",
       "R3  cond  None   1.5   0.3    0.2\n",
       "R4  cond  None  0.05   0.6     12\n",
       "R5  conv    25  None  None   0.04"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "resistances_DF2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\behzad\\\\Dropbox\\\\2 Teaching Activities\\\\00 EETBS 2019\\\\Git repos\\\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\\\ExternalFiles'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.chdir(r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\")\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "resistances_DF2.to_csv(\"ResistanceData.csv\")\n",
    "resistances_DF2.to_excel(\"ResistanceData.xlsx\")\n",
    "resistances_DF2.to_html(\"ResistanceData.html\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There is a better way of doing this without changing the woring directory, we should use the absoloute path of the file !! os.path.join does it for us !"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\\ResistanceData3.html\n"
     ]
    }
   ],
   "source": [
    "os.chdir(r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\")\n",
    "os.getcwd()\n",
    "TablesFolder = r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\"\n",
    "FileName_resistances = \"ResistanceData3.html\"\n",
    "path_file_resistances = os.path.join(TablesFolder,FileName_resistances)\n",
    "print(path_file_resistances)\n",
    "resistances_DF2.to_html(path_file_resistances)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\behzad\\\\Dropbox\\\\2 Teaching Activities\\\\00 EETBS 2019\\\\Git repos\\\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB'"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.getcwd()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Importing Files in Pandas "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Type</th>\n",
       "      <th>DrapesLightOpen</th>\n",
       "      <th>DrapesDarkClosed</th>\n",
       "      <th>DrapesLightClosed</th>\n",
       "      <th>RollerOpaqueDark</th>\n",
       "      <th>RollerOpqaueWhite</th>\n",
       "      <th>RollerTranslucentLight</th>\n",
       "      <th>BlindsMedium</th>\n",
       "      <th>BlindsDark</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1a</th>\n",
       "      <td>clear_1Layer</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0.71</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0.34</td>\n",
       "      <td>0.44</td>\n",
       "      <td>0.74</td>\n",
       "      <td>0.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1c</th>\n",
       "      <td>HeatAbsorbing_1Layer</td>\n",
       "      <td>0.68</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.50</td>\n",
       "      <td>0.67</td>\n",
       "      <td>0.40</td>\n",
       "      <td>0.49</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5a</th>\n",
       "      <td>Clear_2Layer</td>\n",
       "      <td>0.72</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0.57</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.48</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.82</td>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17c</th>\n",
       "      <td>lowEpsillonHighSolar_2Layers</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0.86</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0.82</td>\n",
       "      <td>0.57</td>\n",
       "      <td>0.62</td>\n",
       "      <td>0.86</td>\n",
       "      <td>0.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25a</th>\n",
       "      <td>lowEpsillonLowSolar_2Layers</td>\n",
       "      <td>0.79</td>\n",
       "      <td>0.88</td>\n",
       "      <td>0.68</td>\n",
       "      <td>0.85</td>\n",
       "      <td>0.60</td>\n",
       "      <td>0.66</td>\n",
       "      <td>0.88</td>\n",
       "      <td>0.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5c</th>\n",
       "      <td>HeatAbsorbing_2Layers</td>\n",
       "      <td>0.73</td>\n",
       "      <td>0.82</td>\n",
       "      <td>0.59</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.51</td>\n",
       "      <td>0.58</td>\n",
       "      <td>0.83</td>\n",
       "      <td>0.76</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             Type  DrapesLightOpen  DrapesDarkClosed  \\\n",
       "ID                                                                     \n",
       "1a                   clear_1Layer             0.64              0.71   \n",
       "1c           HeatAbsorbing_1Layer             0.68              0.72   \n",
       "5a                   Clear_2Layer             0.72              0.81   \n",
       "17c  lowEpsillonHighSolar_2Layers             0.76              0.86   \n",
       "25a   lowEpsillonLowSolar_2Layers             0.79              0.88   \n",
       "5c          HeatAbsorbing_2Layers             0.73              0.82   \n",
       "\n",
       "     DrapesLightClosed  RollerOpaqueDark  RollerOpqaueWhite  \\\n",
       "ID                                                            \n",
       "1a                0.45              0.64               0.34   \n",
       "1c                0.50              0.67               0.40   \n",
       "5a                0.57              0.76               0.48   \n",
       "17c               0.64              0.82               0.57   \n",
       "25a               0.68              0.85               0.60   \n",
       "5c                0.59              0.77               0.51   \n",
       "\n",
       "     RollerTranslucentLight  BlindsMedium  BlindsDark  \n",
       "ID                                                     \n",
       "1a                     0.44          0.74        0.66  \n",
       "1c                     0.49          0.76        0.69  \n",
       "5a                     0.55          0.82        0.74  \n",
       "17c                    0.62          0.86        0.79  \n",
       "25a                    0.66          0.88        0.82  \n",
       "5c                     0.58          0.83        0.76  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Folder_whereTheTablesAre = r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\\Tables\"\n",
    "fileName = \"IAC_cl.csv\"\n",
    "path_IAC_cl = os.path.join(Folder_whereTheTablesAre,fileName)\n",
    "\n",
    "IAC_cl_DF  = pd.read_csv(path_IAC_cl, sep =\";\", index_col = 1, header = 0)\n",
    "IAC_cl_DF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.69"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IAC_cl_DF.loc[\"1c\",\"BlindsDark\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "def IAC_cl_finder(windowID,shadingType):\n",
    "    Folder_whereTheTablesAre = r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\\Tables\"\n",
    "    fileName = \"IAC_cl.csv\"\n",
    "    path_IAC_cl = os.path.join(Folder_whereTheTablesAre,fileName)\n",
    "    IAC_cl_DF  = pd.read_csv(path_IAC_cl, sep =\";\", index_col = 1, header = 0)\n",
    "    IAC_cl_ValueForThisInput = IAC_cl_DF.loc[windowID,shadingType]\n",
    "    return IAC_cl_ValueForThisInput\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.69"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IAC_cl_finder(\"1c\",\"BlindsDark\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>width</th>\n",
       "      <th>Height</th>\n",
       "      <th>Area</th>\n",
       "      <th>Window_ID</th>\n",
       "      <th>Frame_type</th>\n",
       "      <th>Frame_material</th>\n",
       "      <th>U</th>\n",
       "      <th>SHGC</th>\n",
       "      <th>HF</th>\n",
       "      <th>...</th>\n",
       "      <th>IAC_cl</th>\n",
       "      <th>IAC</th>\n",
       "      <th>Tx</th>\n",
       "      <th>Ed</th>\n",
       "      <th>ED</th>\n",
       "      <th>PXI</th>\n",
       "      <th>FFs</th>\n",
       "      <th>C_value</th>\n",
       "      <th>CF</th>\n",
       "      <th>Qcooling</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>east</th>\n",
       "      <td>E</td>\n",
       "      <td>8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>west</th>\n",
       "      <td>W</td>\n",
       "      <td>8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>south-Fixed</th>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>south-Operable</th>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0</td>\n",
       "      <td>5c</td>\n",
       "      <td>Operable</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               Direction  width  Height  Area Window_ID Frame_type  \\\n",
       "Name                                                                 \n",
       "east                   E      8     1.8     0        5c      Fixed   \n",
       "west                   W      8     1.8     0        5c      Fixed   \n",
       "south-Fixed            S      2     1.8     0        5c      Fixed   \n",
       "south-Operable         S      2     1.8     0        5c   Operable   \n",
       "\n",
       "               Frame_material  U  SHGC  HF    ...     IAC_cl  IAC    Tx  Ed  \\\n",
       "Name                                          ...                             \n",
       "east                     Wood  0     0   0    ...          0    0  1.00   0   \n",
       "west                     Wood  0     0   0    ...          0    0  1.00   0   \n",
       "south-Fixed              Wood  0     0   0    ...          0    0  1.00   0   \n",
       "south-Operable           Wood  0     0   0    ...          0    0  0.64   0   \n",
       "\n",
       "                ED PXI  FFs  C_value  CF  Qcooling  \n",
       "Name                                                \n",
       "east             0   0    0        0   0         0  \n",
       "west             0   0    0        0   0         0  \n",
       "south-Fixed      0   0    0        0   0         0  \n",
       "south-Operable   0   0    0        0   0         0  \n",
       "\n",
       "[4 rows x 27 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Folder_whereTheTablesAre = r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\\Tables\"\n",
    "fileName_windows = \"windows.csv\"\n",
    "path_windows = os.path.join(Folder_whereTheTablesAre,fileName_windows)\n",
    "windows_DF  = pd.read_csv(path_windows, sep =\";\", index_col = 0, header = 0)\n",
    "windows_DF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.8"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "windows_DF.loc[\"west\",\"Height\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "windows_DF.loc[:,\"Area\"] = windows_DF.loc[:,\"width\"] * windows_DF.loc[:,\"Height\"]  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>width</th>\n",
       "      <th>Height</th>\n",
       "      <th>Area</th>\n",
       "      <th>Window_ID</th>\n",
       "      <th>Frame_type</th>\n",
       "      <th>Frame_material</th>\n",
       "      <th>U</th>\n",
       "      <th>SHGC</th>\n",
       "      <th>HF</th>\n",
       "      <th>...</th>\n",
       "      <th>IAC_cl</th>\n",
       "      <th>IAC</th>\n",
       "      <th>Tx</th>\n",
       "      <th>Ed</th>\n",
       "      <th>ED</th>\n",
       "      <th>PXI</th>\n",
       "      <th>FFs</th>\n",
       "      <th>C_value</th>\n",
       "      <th>CF</th>\n",
       "      <th>Qcooling</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>east</th>\n",
       "      <td>E</td>\n",
       "      <td>8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>14.4</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>west</th>\n",
       "      <td>W</td>\n",
       "      <td>8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>14.4</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>south-Fixed</th>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>3.6</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>south-Operable</th>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>3.6</td>\n",
       "      <td>5c</td>\n",
       "      <td>Operable</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               Direction  width  Height  Area Window_ID Frame_type  \\\n",
       "Name                                                                 \n",
       "east                   E      8     1.8  14.4        5c      Fixed   \n",
       "west                   W      8     1.8  14.4        5c      Fixed   \n",
       "south-Fixed            S      2     1.8   3.6        5c      Fixed   \n",
       "south-Operable         S      2     1.8   3.6        5c   Operable   \n",
       "\n",
       "               Frame_material  U  SHGC  HF    ...     IAC_cl  IAC    Tx  Ed  \\\n",
       "Name                                          ...                             \n",
       "east                     Wood  0     0   0    ...          0    0  1.00   0   \n",
       "west                     Wood  0     0   0    ...          0    0  1.00   0   \n",
       "south-Fixed              Wood  0     0   0    ...          0    0  1.00   0   \n",
       "south-Operable           Wood  0     0   0    ...          0    0  0.64   0   \n",
       "\n",
       "                ED PXI  FFs  C_value  CF  Qcooling  \n",
       "Name                                                \n",
       "east             0   0    0        0   0         0  \n",
       "west             0   0    0        0   0         0  \n",
       "south-Fixed      0   0    0        0   0         0  \n",
       "south-Operable   0   0    0        0   0         0  \n",
       "\n",
       "[4 rows x 27 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "windows_DF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "FileName_windows_modified= \"windows_modified.csv\"\n",
    "path_windows_modified = os.path.join(Folder_whereTheTablesAre,FileName_windows_modified)\n",
    "windows_DF.to_csv(path_windows_modified, sep = \";\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.426\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Name\n",
       "east              2.426\n",
       "west              2.426\n",
       "south-Fixed       2.426\n",
       "south-Operable    2.426\n",
       "Name: C_value, dtype: float64"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "latitude  = 45\n",
    "location_deltaT_cooling = 7.9 \n",
    "location_deltaT_heating = 24.9 \n",
    "location_DR_cooling= 11.9\n",
    "\n",
    "C_Value  =location_deltaT_cooling - 0.46 * location_DR_cooling\n",
    "print(C_Value)\n",
    "windows_DF.loc[:,\"C_value\"] = C_Value\n",
    "windows_DF.loc[:,\"C_value\"] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "windows_DF.to_csv(path_windows_modified, sep = \";\")\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "def IAC_cl_finder_BlindsDark(windowID):\n",
    "    shadingType = \"BlindsDark\"\n",
    "    Folder_whereTheTablesAre = r\"C:\\Users\\behzad\\Dropbox\\2 Teaching Activities\\00 EETBS 2019\\Git repos\\python4ScientificComputing_Numpy_Pandas_MATPLotLIB\\ExternalFiles\\Tables\"\n",
    "    fileName = \"IAC_cl.csv\"\n",
    "    path_IAC_cl = os.path.join(Folder_whereTheTablesAre,fileName)\n",
    "    IAC_cl_DF  = pd.read_csv(path_IAC_cl, sep =\";\", index_col = 1, header = 0)\n",
    "    IAC_cl_ValueForThisInput = IAC_cl_DF.loc[windowID,shadingType]\n",
    "    return IAC_cl_ValueForThisInput"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name\n",
       "east              0\n",
       "west              0\n",
       "south-Fixed       0\n",
       "south-Operable    0\n",
       "Name: IAC_cl, dtype: int64"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "windows_DF.loc[:,\"IAC_cl\"] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Name\n",
       "east              0.76\n",
       "west              0.76\n",
       "south-Fixed       0.76\n",
       "south-Operable    0.76\n",
       "Name: Window_ID, dtype: float64"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "windows_DF.loc[:,\"Window_ID\"].apply(IAC_cl_finder_BlindsDark)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "windows_DF.loc[:,\"IAC_cl\"]  = windows_DF.loc[:,\"Window_ID\"].apply(IAC_cl_finder_BlindsDark)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>width</th>\n",
       "      <th>Height</th>\n",
       "      <th>Area</th>\n",
       "      <th>Window_ID</th>\n",
       "      <th>Frame_type</th>\n",
       "      <th>Frame_material</th>\n",
       "      <th>U</th>\n",
       "      <th>SHGC</th>\n",
       "      <th>HF</th>\n",
       "      <th>...</th>\n",
       "      <th>IAC_cl</th>\n",
       "      <th>IAC</th>\n",
       "      <th>Tx</th>\n",
       "      <th>Ed</th>\n",
       "      <th>ED</th>\n",
       "      <th>PXI</th>\n",
       "      <th>FFs</th>\n",
       "      <th>C_value</th>\n",
       "      <th>CF</th>\n",
       "      <th>Qcooling</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>east</th>\n",
       "      <td>E</td>\n",
       "      <td>8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>14.4</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.426</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>west</th>\n",
       "      <td>W</td>\n",
       "      <td>8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>14.4</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.426</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>south-Fixed</th>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>3.6</td>\n",
       "      <td>5c</td>\n",
       "      <td>Fixed</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.426</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>south-Operable</th>\n",
       "      <td>S</td>\n",
       "      <td>2</td>\n",
       "      <td>1.8</td>\n",
       "      <td>3.6</td>\n",
       "      <td>5c</td>\n",
       "      <td>Operable</td>\n",
       "      <td>Wood</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.76</td>\n",
       "      <td>0</td>\n",
       "      <td>0.64</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2.426</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               Direction  width  Height  Area Window_ID Frame_type  \\\n",
       "Name                                                                 \n",
       "east                   E      8     1.8  14.4        5c      Fixed   \n",
       "west                   W      8     1.8  14.4        5c      Fixed   \n",
       "south-Fixed            S      2     1.8   3.6        5c      Fixed   \n",
       "south-Operable         S      2     1.8   3.6        5c   Operable   \n",
       "\n",
       "               Frame_material  U  SHGC  HF    ...     IAC_cl  IAC    Tx  Ed  \\\n",
       "Name                                          ...                             \n",
       "east                     Wood  0     0   0    ...       0.76    0  1.00   0   \n",
       "west                     Wood  0     0   0    ...       0.76    0  1.00   0   \n",
       "south-Fixed              Wood  0     0   0    ...       0.76    0  1.00   0   \n",
       "south-Operable           Wood  0     0   0    ...       0.76    0  0.64   0   \n",
       "\n",
       "                ED PXI  FFs  C_value  CF  Qcooling  \n",
       "Name                                                \n",
       "east             0   0    0    2.426   0         0  \n",
       "west             0   0    0    2.426   0         0  \n",
       "south-Fixed      0   0    0    2.426   0         0  \n",
       "south-Operable   0   0    0    2.426   0         0  \n",
       "\n",
       "[4 rows x 27 columns]"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "windows_DF"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
